package command

import (
	"fmt"
	"github.com/spf13/cobra"
	"os"
)

var createfileCmd = &cobra.Command{
	Use:   "create [file]",
	Short: "Create a new file",
	Long:  `Create a new file with the specified name.`,
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		fileName := args[0]
		if _, err := os.Stat(fileName); err == nil {
			fmt.Printf("File %s already exists\n", fileName)
			return
		}
		file, err := os.Create(fileName)
		if err != nil {
			fmt.Println(err)
			return
		}
		defer file.Close()
		fmt.Printf("File %s created\n", fileName)
	},
}

var deletefileCmd = &cobra.Command{
	Use:   "remove [file]",
	Short: "Remove a file",
	Long:  `Delete the file with the specified name.`,
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		fileName := args[0]
		if _, err := os.Stat(fileName); err != nil {
			if os.IsNotExist(err) {
				fmt.Printf("File %s does not exist\n", fileName)
			} else {
				fmt.Println(err)
			}
			return
		}
		err := os.Remove(fileName)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Printf("File %s removed\n", fileName)
	},
}
